package org.feng.demofx.vo;

import lombok.Data;
import org.feng.demofx.entity.Animal;
import org.feng.demofx.enums.AnimalTypeEnum;
import org.feng.demofx.sys.TableColumnDesc;

import java.util.Objects;

/**
 * TODO
 *
 * @author feng
 */
@Data
public class AnimalVo {
    @TableColumnDesc(value = "编号")
    private Integer id;
    @TableColumnDesc(value = "名字", order = 1, editable = true)
    private String name;
    @TableColumnDesc(value = "年龄", order = 3, editable = true)
    private Integer age = 0;
    @TableColumnDesc(value = "动物类型", order = 2)
    private String animalType;

    public static AnimalVo newInstance(Animal animal) {
        AnimalVo animalVo = new AnimalVo();
        animalVo.setId(animal.getId().intValue());
        animalVo.setName(animal.getName());
        animalVo.setAge(animal.getAge());
        if (Objects.isNull(animal.getAnimalType())) {
            animal.setAnimalType(AnimalTypeEnum.UN_KNOW);
        }
        animalVo.setAnimalType(animal.getAnimalType().getDesc());
        return animalVo;
    }
}
